﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace CaseStudy.Web.UserControl
{
    public partial class CaseStudyItem : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
        }

        public CaseStudyItem(string id, string title, string client, string imgUrl)
        {
            Panel panel = new Panel();

            string clientName = client;
            if (client.Length > 30)
            {
                client = client.Substring(0, 27) + "......";
            }

            string titleName = title;
            if (title.Length > 54)
            {
                title = title.Substring(0, 51) + "......";
            }

            HtmlTable table = new HtmlTable();
            HtmlTableRow rowTop = new HtmlTableRow();
            HtmlTableRow rowBottom = new HtmlTableRow();

            HtmlTableCell cellTopLeft = new HtmlTableCell();
            HtmlTableCell cellTopRight = new HtmlTableCell();
            HtmlTableCell cellBottom = new HtmlTableCell();

            cellTopLeft.InnerHtml = string.Format("<image src=\"{0}\" title=\"{1}\" />", imgUrl, title);
            cellTopRight.InnerText = client;
            cellBottom.InnerText = title;
            cellBottom.Attributes.Add("colspan", "2");

            //link.NavigateUrl = "CaseStudyView.aspx?id=" + id;

            rowTop.Controls.Add(cellTopLeft);
            rowTop.Controls.Add(cellTopRight);
            rowBottom.Controls.Add(cellBottom);

            table.Attributes.Add("onclick", "javascript:window.location.href='CaseStudyView.aspx?id=" + id + "'");
            table.Controls.Add(rowTop);
            table.Controls.Add(rowBottom);

            panel.Controls.Add(table);

            this.Controls.Add(panel);

            table.Attributes.Add("class", "CaseStudyItem");
            table.Attributes.Add("cellspacing", "0");
            cellTopLeft.Attributes.Add("class", "ItemImage");
            cellTopRight.Attributes.Add("class", "ItemClientText");
            cellBottom.Attributes.Add("class", "ItemTitleText");
            cellTopRight.Attributes.Add("title", clientName);
            cellBottom.Attributes.Add("title", titleName);
            panel.CssClass = "ItemPanel";

        }
    }
}